<?php


namespace app\common\cachemodel;


use app\common\model\BaseCache;
use XznsTools\cache\CacheManage;

class AppConfig extends BaseCache
{
    protected $table = 'wechat_backup_07_18_14_43_00.app_config';
    protected $cacheModel = 'config.app';

    /**
     * app配置
     * @param $name
     * @return array|bool|mixed|string
     * @throws \Exception
     */
    public function configInfo($name)
    {
        $data = CacheManage::getInstance()->setCacheConfig($this->cacheModel, $name)->getDataAndSet(function () use ($name)
        {
            try
            {
                $config = $this->where(['name' => $name])->field('value')->findOrFail()->toArray();
                $config = json_decode($config['value'], true);
                $data = [];
                foreach ($config as $k => $item)
                {
                    $data[$item['name']] = $item['value'];
                }
            }
            catch (\Exception $e)
            {
                $data = [];
            }
            return $data;
        });
        if (is_string($data))
        {
            $data = json_decode($data, true);
        }
        return $data;
    }
}